from django.db import models


# Create your models here.


# 创建床铺模型
class Bed(models.Model):
    image = models.ImageField(upload_to='beds/%Y/%m', verbose_name='床铺图片')
    name = models.CharField(max_length=20, verbose_name='床铺名称')
    description = models.TextField(verbose_name='床铺描述')
    price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='床铺价格')
    num = models.IntegerField(verbose_name='床铺数量')
    hotel = models.ForeignKey('Hotel', on_delete=models.CASCADE, verbose_name='所属酒店')
    start_time = models.DateTimeField(verbose_name='开始时间')
    end_time = models.DateTimeField(verbose_name='结束时间')

    class Meta:
        db_table = 'beds'

    def __str__(self):
        return self.name


# 创建酒店模型
class Hotel(models.Model):
    name = models.CharField(max_length=20, verbose_name='酒店名称')

    class Meta:
        db_table = 'hotels'

    def __str__(self):
        return self.name

# 订单模型
class Order(models.Model):
    user = models.CharField(max_length=20, verbose_name='用户')
    phone = models.CharField(max_length=20, verbose_name='手机号')
    hotel = models.ForeignKey('Hotel', on_delete=models.CASCADE, verbose_name='所属酒店')
    bed = models.ForeignKey('Bed', on_delete=models.CASCADE, verbose_name='床铺')
    start_date = models.DateField(verbose_name='入住时间',null=True,blank=True)
    end_date = models.DateField(verbose_name='离店时间',null=True,blank=True)
    num = models.IntegerField(verbose_name='预订数量',null=True,blank=True)
    total_price = models.DecimalField(max_digits=10, decimal_places=2, verbose_name='总价',null=True,blank=True)
    status = models.CharField(max_length=20, verbose_name='订单状态',null=True,blank=True)

    class Meta:
        db_table = 'orders'

